-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add line # of previous definition (resubmit #3396) #3424
Changes from 5 commits
82c5313
5b077ae
39c3058
8449ed5
295c203
e1bfb11
3d77de6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,16 +165,16 @@ import typing | |
class A: pass | ||
class A: pass | ||
[out] | ||
main:3: error: Name 'A' already defined | ||
main:3: error: Name 'A' already defined on line 2 | ||
|
||
[case testMultipleMixedDefinitions] | ||
import typing | ||
x = 1 | ||
def x(): pass | ||
class x: pass | ||
[out] | ||
main:3: error: Name 'x' already defined | ||
main:4: error: Name 'x' already defined | ||
main:3: error: Name 'x' already defined on line 2 | ||
main:4: error: Name 'x' already defined on line 2 | ||
|
||
[case testNameNotImported] | ||
import typing | ||
|
@@ -1037,13 +1037,13 @@ t = 1 # E: Invalid assignment target | |
[case testRedefineTypevar2] | ||
from typing import TypeVar | ||
t = TypeVar('t') | ||
def t(): pass # E: Name 't' already defined | ||
def t(): pass # E: Name 't' already defined on line 2 | ||
[out] | ||
|
||
[case testRedefineTypevar3] | ||
from typing import TypeVar | ||
t = TypeVar('t') | ||
class t: pass # E: Name 't' already defined | ||
class t: pass # E: Name 't' already defined on line 2 | ||
[out] | ||
|
||
[case testRedefineTypevar4] | ||
|
@@ -1330,3 +1330,13 @@ a = ('spam', 'spam', 'eggs', 'spam') # type: Tuple[str] | |
[out] | ||
main:3: error: Name 'a' already defined | ||
main:4: error: Name 'a' already defined | ||
|
||
[case testUnknownContextDuplicateDef] | ||
from m import A | ||
class A: | ||
pass | ||
[file m.py] | ||
class A: | ||
pass | ||
[out] | ||
main:2: error: Name 'A' already defined (line unavailable; possibly an import) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here are further ideas for test cases:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a module is simply imported twice, there's no error message. Did you mean some other test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pkch Maybe Jukka means something like this: import re
re = 1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but that will cause a completely different error message (types are not compatible). It won't get to the point of complaining about duplicate definition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And what about import re
import math
re = math There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, there's no error message at all (as expected?). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could simplify the message a bit. What about just
(possibly by an import)
. The 'line unavailable' part doesn't provide useful information really.