Title: PLS doesn't flag error in a relative import if it is found in another root directory · Issue #509 · microsoft/python-language-server · GitHub
Open Graph Title: PLS doesn't flag error in a relative import if it is found in another root directory · Issue #509 · microsoft/python-language-server
X Title: PLS doesn't flag error in a relative import if it is found in another root directory · Issue #509 · microsoft/python-language-server
Description: The analyzer incorrectly accepts relative imports in cases where the path is relative to a root but not to the importing file. Consider the following case: Directory structure: src |->module |--->init.py test.py PYTHONPATH=src test.py co...
Open Graph Description: The analyzer incorrectly accepts relative imports in cases where the path is relative to a root but not to the importing file. Consider the following case: Directory structure: src |->module |--->i...
X Description: The analyzer incorrectly accepts relative imports in cases where the path is relative to a root but not to the importing file. Consider the following case: Directory structure: src |->module |--...
Opengraph URL: https://github.com/microsoft/python-language-server/issues/509
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PLS doesn't flag error in a relative import if it is found in another root directory","articleBody":"The analyzer incorrectly accepts relative imports in cases where the path is relative to a root but not to the importing file.\r\n\r\nConsider the following case:\r\nDirectory structure:\r\nsrc\r\n|-\u003emodule\r\n|---\u003e__init__.py\r\ntest.py\r\n\r\nPYTHONPATH=src\r\n\r\ntest.py contains the following code:\r\n```\r\nfrom .module import Foo\r\n```\r\n\r\nThis import should be flagged as invalid because the path \".module\" should be relative to the test.py file. However, the code in `PathResolverSnapshot.GetImportsFromRelativePath` considers all of the root search directories when it performs its search. It therefore finds an import match when it shouldn't.\r\n\r\nI think the problem is in `PathResolverSnapshot.RootContains`. It doesn't do anything to validate that the specified lastEdge starts in the same location as the root. If the relative path happens to match items within that root, the method returns true. If the relative path is zero length, all roots return true.\r\n\r\nA proposed fix is to add the following piece of code to `PathResolverSnapshot.RootContains` before the while loop:\r\n\r\n```\r\nif (root != sourceEdge.Next.Start) {\r\n rootEdge = default;\r\n return false;\r\n}\r\n```","author":{"url":"https://github.com/erictraut","@type":"Person","name":"erictraut"},"datePublished":"2018-12-26T04:40:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/509/python-language-server/issues/509"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:878edd14-6da4-6fb4-352c-fb64deeb73c0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E1C:25C9D0:162A563:1EAD770:6A4DF225 |
| html-safe-nonce | e0067bff3d9b05558cb47eae09014b3311a15323b552a19a2c6fdbd6711a6329 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTFDOjI1QzlEMDoxNjJBNTYzOjFFQUQ3NzA6NkE0REYyMjUiLCJ2aXNpdG9yX2lkIjoiMzk0OTk0MDczNzk2NTk0NTM4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 78fc84b936472c641f6dd50071bf3e2d02581efbb9a052ba32482d75b5cf608a |
| hovercard-subject-tag | issue:394080442 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/python-language-server/509/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d0565991f6607ca929db725881347e7afaeec0fc7d7d5db7f199522fb8fc69a9/microsoft/python-language-server/issues/509 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d0565991f6607ca929db725881347e7afaeec0fc7d7d5db7f199522fb8fc69a9/microsoft/python-language-server/issues/509 |
| og:image:alt | The analyzer incorrectly accepts relative imports in cases where the path is relative to a root but not to the importing file. Consider the following case: Directory structure: src |->module |--->i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | erictraut |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5818716c93c6a2925b815402541a32814e43a7b1261c322b0c2df75224289566 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/python-language-server git https://github.com/microsoft/python-language-server.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 145901977 |
| octolytics-dimension-repository_nwo | microsoft/python-language-server |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 145901977 |
| octolytics-dimension-repository_network_root_nwo | microsoft/python-language-server |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f4bb89367ca678f057d79b1abc45d6675b1bd5b2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width