-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Misplaced type annotation #5696
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
Comments
Seems like a problem in https://github.com/python/typed_ast |
I cannot reproduce this. Maybe there is something else you didn't mention? |
Here it is from the beginning of the file (excluding imports): file_path = Path(__file__)
protocol_schema_path = file_path.parent / "slim_chronic_protocol.schema.json"
onboarding_protocols_path = file_path.parent / 'slim_chronic_onboarding_protocols'
preshare_protocols_path = file_path.parent / 'slim_chronic_preshare_protocols'
with protocol_schema_path.open() as file:
protocol_schema = json.load(file)
protocol_validator = Draft6Validator(protocol_schema)
def read_protocol(protocol_path: Path) -> protocol.RawProtocol:
with protocol_path.open() as file:
raw_protocol = json.load(file)
protocol_validator.validate(raw_protocol)
return raw_protocol
onboarding_protocols: Dict[str, protocol.RawProtocol] = {
protocol_path.stem: read_protocol(protocol_path)
for protocol_path in onboarding_protocols_path.glob('*.json')
}
preshare_protocols: Dict[str, protocol.RawProtocol] = {
protocol_path.stem: read_protocol(protocol_path)
for protocol_path in preshare_protocols_path.glob('*.json')
} |
I just tried this, and this works perfectly. What is the version of |
1.1.0 |
And on what line exactly do you get the error? |
I get the error on the line before |
Are you sure you get the error in this file? Maybe you have a file with a similar name or |
@iddan I think we're not going to get to the bottom of this until you post a completely self-contained repro, something that anybody can copy/paste into a file and run mypy over. |
This is a company secret closed source. |
So you cannot boil it down to something you can share? Then we have to close this issue. |
It was another file. I have no idea why it wasn't reported in VSCode for the wrong location. |
So it seems like commented out code is failing: # @attrs(auto_attribs=True)
# class Attribute:
# id: str
# name: str
# values: List[Value] = attrib(convert=partial(convert_, Value))
# type: str = attrib(convert=lambda t: t if isinstance(t, str) else t.name)
#
# def __contains__(self, item):
# return item in self.__dict__
#
# def __getitem__(self, item):
# return self.__dict__[item] |
And this is expected, because on line 6 of your snippet there is
which is a type comment. You can just put two comment signs to suppress this |
It will be good if this syntax would be prohibited eventually |
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
error:misplaced type annotation
Do you see the same issue after installing mypy from Git master? Yes
the full traceback below.
The text was updated successfully, but these errors were encountered: