Skip to content
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

Mypy errors accessing resources fields #60

Open
ItayGoren opened this issue Mar 3, 2021 · 4 comments
Open

Mypy errors accessing resources fields #60

ItayGoren opened this issue Mar 3, 2021 · 4 comments

Comments

@ItayGoren
Copy link
Contributor

Im using python 3.8 and trying to upgrade from version 6.0.0b5 to 6.1.0.
The code is

from fhir.resources.codeableconcept import CodeableConcept
from fhir.resources.condition import Condition

Condition(subject={}, code=CodeableConcept()).code.coding

When using version 6.0.0b5 and running mypy --ignore-missing-imports a.py I get:
Success: no issues found in 1 source file

Using version 6.1.0 and running the same function I get:

a.py:4: error: "CodeableConceptType" has no attribute "coding"
Found 1 error in 1 file (checked 1 source file)

Looking at the classes, we can see that the annotations are using FooType, for example CodeableConceptType and not CodeableConcept which makes mypy not being able to parse the library.
If I understand correctly, the rational to use FooType classes is otherwise we would have circle imports.

How can we make mypy parse this library?
Or, what changed between 6.0.0b5 to 6.1.0 that can affect it? Were type hints added to the library? If so, I think its wrong to do so :)

@nazrulworld
Copy link
Owner

Related issue #58

I don't think we did some changes (from 6.0.0b5 to 6.1.0) related to Mypy/linting.

Are you using the same mypy version or upgraded?

@ItayGoren
Copy link
Contributor Author

same one. the problem is that we didnt have typing before - it didnt find it and because i use --ignore-missing-imports i had no problems

@ItayGoren
Copy link
Contributor Author

I continued to think about this problem and correct me if im wrong, but the ClassNameType is used because without it there is a circular imports flow. This circle occur because of Extensions which holds primitives and each primitive holds Extension. Is that the case?
If so, putting all of them in the same file would solve it. What do you think about it?
Another solution, is specifying the annotations in Extension using strings and not classes and do that only there.
What do you think? @nazrulworld

@nazrulworld
Copy link
Owner

you are right that primarly ClassNameType is used to solve FHIR's two-way relationship which introducing circular dependency. but this typing is also used as Pydantic field validator!

putting all of them in the same file would solve it. What do you think about it? I don't think that will solve the problem beside the problem, not just inside Extension, other places as well.
For example see relationship between Element <-> Extension class.

Another solution, is specifying the annotations in Extension using strings and not classes and do that only there.
That could be a good idea, let's try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants