Skip to content

Commit

Permalink
mypy configured. improvements after linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
pedropaulofb committed Dec 7, 2023
1 parent e673c01 commit eae745a
Show file tree
Hide file tree
Showing 35 changed files with 169 additions and 86 deletions.
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ repos:
language: system
types: [ python ]
pass_filenames: true
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
hooks:
- id: mypy
args: [ -p=ontouml_py ]
language: system
types: [ python ]
pass_filenames: false
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ Classes
a part of the project's elements. If the validation fails, a ValueError is raised.

:param key: The name of the attribute to be set.
:param value: The value to be assigned to the attribute.
:type key: str
:param value: The value to be assigned to the attribute.
:type value: Any
:raises ValueError: If 'root_package' is set to a package not in the project's elements.

Expand Down
2 changes: 1 addition & 1 deletion docs/_sources/autoapi/ontouml_py/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@ Classes
a part of the project's elements. If the validation fails, a ValueError is raised.

:param key: The name of the attribute to be set.
:param value: The value to be assigned to the attribute.
:type key: str
:param value: The value to be assigned to the attribute.
:type value: Any
:raises ValueError: If 'root_package' is set to a package not in the project's elements.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ <h3>Classes<a class="headerlink" href="#classes" title="Link to this heading">
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>ValueError</strong> – If ‘general’ and ‘specific’ classifiers are the same.</p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p>None</p>
</dd>
</dl>
</dd></dl>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ <h3>Classes<a class="headerlink" href="#classes" title="Link to this heading">
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><strong>ValueError</strong> – If ‘root_package’ is set to a package not in the project’s elements.</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>None</p>
</dd>
</dl>
</dd></dl>

Expand Down Expand Up @@ -312,6 +315,9 @@ <h3>Classes<a class="headerlink" href="#classes" title="Link to this heading">
<li><p><strong>ValueError</strong> – If the package is not included in the project’s elements or is not a valid Package instance.</p></li>
</ul>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>None</p>
</dd>
</dl>
</dd></dl>

Expand Down
9 changes: 9 additions & 0 deletions docs/autoapi/ontouml_py/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ <h3>Classes<a class="headerlink" href="#classes" title="Link to this heading">
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>ValueError</strong> – If ‘general’ and ‘specific’ classifiers are the same.</p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p>None</p>
</dd>
</dl>
</dd></dl>

Expand Down Expand Up @@ -823,6 +826,9 @@ <h3>Classes<a class="headerlink" href="#classes" title="Link to this heading">
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><strong>ValueError</strong> – If ‘root_package’ is set to a package not in the project’s elements.</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>None</p>
</dd>
</dl>
</dd></dl>

Expand Down Expand Up @@ -871,6 +877,9 @@ <h3>Classes<a class="headerlink" href="#classes" title="Link to this heading">
<li><p><strong>ValueError</strong> – If the package is not included in the project’s elements or is not a valid Package instance.</p></li>
</ul>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>None</p>
</dd>
</dl>
</dd></dl>

Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ontouml_py/classes/abstract_classes/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Classifier(Decoratable, Packageable):
# Public attributes
is_abstract: bool = Field(default=False)

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"validate_default": True,
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/abstract_classes/decoratable.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Decoratable(ModelElement):

is_derived: bool = Field(default=False)

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"extra": "forbid",
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/abstract_classes/modelelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ModelElement(NamedElement, ProjectElement):

custom_properties: set[tuple[str, Any]] = Field(default_factory=set)

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"extra": "forbid",
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/abstract_classes/namedelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class NamedElement(OntoumlElement):
creators: set[str] = Field(default_factory=set) # Empty strings are not allowed in the list
contributors: set[str] = Field(default_factory=set) # Empty strings are not allowed in the list

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"extra": "forbid",
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/abstract_classes/ontoumlelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class OntoumlElement(ABC, BaseModel):
created: datetime = Field(default_factory=datetime.now)
modified: Optional[datetime] = Field(default=None)

model_config = { # noqa (vulture)
model_config = {
"validate_assignment": True,
"extra": "forbid",
"str_strip_whitespace": True,
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/abstract_classes/packageable.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Packageable(ModelElement):

_in_package: Optional["Package"] = PrivateAttr(default=None) # noqa: F821 (flake8)

model_config = { # noqa (vulture)
model_config = {
"validate_assignment": True,
"extra": "forbid",
"str_strip_whitespace": True,
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/abstract_classes/projectelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ProjectElement(OntoumlElement):

_in_project: Optional["Project"] = PrivateAttr(default=None) # noqa: F821 (flake8)

model_config = { # noqa (vulture)
model_config = {
"validate_assignment": True,
"extra": "forbid",
"str_strip_whitespace": True,
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/abstract_classes/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Relation(Classifier):

stereotype: Optional[RelationStereotype] = Field(default=None)

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"validate_default": True,
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/concrete_classes/anchor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Anchor(ModelElement):
note: Note = Field()
target: ModelElement = Field()

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"extra": "forbid",
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/concrete_classes/binaryrelation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BinaryRelation(Relation):
:vartype model_config: Dict[str, Any]
"""

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"validate_default": True,
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/concrete_classes/class_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Class(Classifier):
stereotype: ClassStereotype = Field()
literals: set[Literal] = Field(default_factory=set)

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"validate_default": True,
Expand Down
4 changes: 2 additions & 2 deletions ontouml_py/classes/concrete_classes/generalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Generalization(ModelElement):
general: Classifier = Field()
specific: Classifier = Field()

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"validate_default": True,
Expand All @@ -41,7 +41,7 @@ class Generalization(ModelElement):
}

@model_validator(mode="after")
def __ensure_irreflexive(self):
def __ensure_irreflexive(self) -> None:
"""Validate that the generalization relationship is irreflexive.
Ensures that the 'general' and 'specific' classifiers are different, as a classifier cannot generalize itself.
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/concrete_classes/generalizationset.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class GeneralizationSet(ModelElement):
generalizations: set[object] = Field(min_length=1, default_factory=set)
categorizer: Optional[object] = Field(default=None)

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"extra": "forbid",
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/concrete_classes/literal.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Literal(ModelElement):
:vartype model_config: Dict[str, Any]
"""

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"validate_default": True,
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/concrete_classes/naryrelation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class and inherits its properties and methods.
:vartype model_config: Dict[str, Any]
"""

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"validate_default": True,
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/concrete_classes/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Note(ModelElement):

text: LangString = Field()

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"extra": "forbid",
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/concrete_classes/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Package(Packageable):
# Private attribute
_contents: set[Packageable] = PrivateAttr(default_factory=set)

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"extra": "forbid",
Expand Down
9 changes: 4 additions & 5 deletions ontouml_py/classes/concrete_classes/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import Any
from typing import Optional

from icecream import ic
from pydantic import Field
from pydantic import field_validator
from pydantic import PrivateAttr
Expand Down Expand Up @@ -85,7 +84,7 @@ class Project(NamedElement):
root_package: Optional[Package] = Field(default=None)
representation_style: OntologyRepresentationStyle = Field(default=OntologyRepresentationStyle.ONTOUML_STYLE)

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"extra": "forbid",
Expand Down Expand Up @@ -120,15 +119,15 @@ def __init__(self, **data: dict[str, Any]) -> None:
if "root_package" in data:
self.__validate_root_package(data.get("root_package"))

def __setattr__(self, key, value):
def __setattr__(self, key: str, value: Any) -> None:
"""Override the default attribute setting behavior to include validation for 'root_package'.
This method intercepts the setting of the 'root_package' attribute to ensure that the assigned package is
a part of the project's elements. If the validation fails, a ValueError is raised.
:param key: The name of the attribute to be set.
:param value: The value to be assigned to the attribute.
:type key: str
:param value: The value to be assigned to the attribute.
:type value: Any
:raises ValueError: If 'root_package' is set to a package not in the project's elements.
"""
Expand Down Expand Up @@ -178,7 +177,7 @@ def __ensure_non_empty(cls, checked_values: set[str], checked_field: ValidationI
raise ValueError(error_message)
return checked_values

def __validate_root_package(self, package: Optional[Package]):
def __validate_root_package(self, package: Optional[Package]) -> None:
"""Validate if the provided package is a valid root package for the project.
This method performs two checks:
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/concrete_classes/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Property(Decoratable):
subsetted_by: set["Property"] = Field(default_factory=set)
redefined_by: set["Property"] = Field(default_factory=set)

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"extra": "forbid",
Expand Down
2 changes: 1 addition & 1 deletion ontouml_py/classes/datatypes/cardinality.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Cardinality(BaseModel):
is_ordered: bool = Field(default=False)
is_unique: bool = Field(default=True)

model_config = { # noqa (vulture)
model_config = {
"arbitrary_types_allowed": True,
"validate_assignment": True,
"extra": "forbid",
Expand Down
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ sphinx-toolbox = "^3.5.0"
myst-parser = "^2.0.0"
# Flake8 and plugins
flake8 = "^6.1.0"
flake8-broken-line = "^1.0.0"
flake8-fixme = "^1.1.1"
flake8-implicit-str-concat = "^0.4.0"
flake8-noqa = "^1.3.2"
Expand All @@ -60,12 +61,26 @@ line-length = 120
[tool.vulture]
paths = ["."]
exclude = ["docs/", "sphinx/", "ontouml_py/classes/enumerations/", "venv/"]
min_confidence = 61

[tool.mypy]
exclude = '^tests'
exclude = ['tests']
strict = true
plugins = "pydantic.mypy"

follow_imports = "silent"
warn_redundant_casts = true
warn_unused_ignores = true
disallow_any_generics = true
check_untyped_defs = true
no_implicit_reexport = true
disallow_untyped_defs = true

[tool.pydantic-mypy]
init_forbid_extra = true
init_typed = true
warn_required_dynamic_aliases = true

[tool.pylint]
ignore-paths = '^(tests|docs|sphinx)'
max-line-length = 120
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ fastjsonschema==2.19.0 ; python_version >= "3.09" and python_version < "4.0" \
filelock==3.13.1 ; python_version >= "3.09" and python_version < "4.0" \
--hash=sha256:521f5f56c50f8426f5e03ad3b281b490a87ef15bc6c526f168290f0c7148d44e \
--hash=sha256:57dbda9b35157b05fb3e58ee91448612eb674172fab98ee235ccb0b5bee19a1c
flake8-broken-line==1.0.0 ; python_version >= "3.09" and python_version < "4.0" \
--hash=sha256:96c964336024a5030dc536a9f6fb02aa679e2d2a6b35b80a558b5136c35832a9 \
--hash=sha256:e2c6a17f8d9a129e99c1320fce89b33843e2963871025c4c2bb7b8b8d8732a85
flake8-fixme==1.1.1 ; python_version >= "3.09" and python_version < "4.0" \
--hash=sha256:226a6f2ef916730899f29ac140bed5d4a17e5aba79f00a0e3ae1eff1997cb1ac \
--hash=sha256:50cade07d27a4c30d4f12351478df87339e67640c83041b664724bda6d16f33a
Expand Down
Loading

0 comments on commit eae745a

Please sign in to comment.