Skip to content

Commit

Permalink
Fix mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Dec 12, 2023
1 parent 6fa6350 commit af0325b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
34 changes: 17 additions & 17 deletions fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ def create(
if texts:
nb_pages = len(texts)
else:
texts = self.faker.sentences(nb=nb_pages) # type: ignore
texts = self.faker.sentences(nb=nb_pages)

if metadata:
metadata.add_content(texts) # type: ignore
Expand Down Expand Up @@ -1774,8 +1774,8 @@ def __init_subclass__(cls, **kwargs):
cls.__bases__[0],
"_meta",
{
attr: getattr(cls.__bases__[0].Meta, attr)
for attr in dir(cls.__bases__[0].Meta)
attr: getattr(cls.__bases__[0].Meta, attr) # type: ignore
for attr in dir(cls.__bases__[0].Meta) # type: ignore
if not attr.startswith("_")
},
)
Expand All @@ -1785,7 +1785,7 @@ def __init_subclass__(cls, **kwargs):
if not attr.startswith("_")
}

cls._meta = {**base_meta, **cls_meta}
cls._meta = {**base_meta, **cls_meta} # type: ignore

@classmethod
def _run_hooks(cls, hooks, instance):
Expand Down Expand Up @@ -1870,7 +1870,7 @@ def save(cls, instance):
@classmethod
def create(cls, **kwargs):
model = cls.Meta.model # type: ignore
unique_fields = cls._meta.get("get_or_create", ["id"])
unique_fields = cls._meta.get("get_or_create", ["id"]) # type: ignore

# Construct a query for unique fields
query = {
Expand Down Expand Up @@ -1973,7 +1973,7 @@ async def async_save():
@classmethod
def create(cls, **kwargs):
model = cls.Meta.model # type: ignore
unique_fields = cls._meta.get("get_or_create", ["id"])
unique_fields = cls._meta.get("get_or_create", ["id"]) # type: ignore

# Construct a query for unique fields
query = {
Expand Down Expand Up @@ -2069,7 +2069,7 @@ def create(cls, **kwargs):
session = cls.MetaSQLAlchemy.get_session() # type: ignore

model = cls.Meta.model # type: ignore
unique_fields = cls._meta.get("get_or_create", ["id"])
unique_fields = cls._meta.get("get_or_create", ["id"]) # type: ignore

# Check for existing instance
if unique_fields:
Expand Down Expand Up @@ -2145,7 +2145,7 @@ class ClassProperty(property):

def __get__(self, cls, owner):
"""Get."""
return classmethod(self.fget).__get__(None, owner)()
return classmethod(self.fget).__get__(None, owner)() # type: ignore


classproperty = ClassProperty
Expand Down Expand Up @@ -2247,7 +2247,7 @@ def test_email(self) -> None:
for domain, expected_domain in domains:
with self.subTest(domain=domain, expected_domain=expected_domain):
kwargs = {"domain": domain}
email: str = self.faker.email(**kwargs) # type: ignore
email: str = self.faker.email(**kwargs)
self.assertIsInstance(email, str)
self.assertTrue(email.endswith(f"@{expected_domain}"))

Expand Down Expand Up @@ -2507,7 +2507,7 @@ def test_text_pdf(self) -> None:
with self.subTest("All params None, should fail"):
with self.assertRaises(ValueError):
self.faker.pdf(
nb_pages=None, # type: ignore
nb_pages=None,
texts=None,
generator=TextPdfGenerator,
)
Expand Down Expand Up @@ -2561,14 +2561,14 @@ def test_image(self):
for image_format in {"png", "svg", "bmp", "gif"}:
with self.subTest(image_format=image_format):
image = self.faker.image(
image_format=image_format, # type: ignore
image_format=image_format,
)
self.assertTrue(image)
self.assertIsInstance(image, bytes)
for image_format in {"bin"}:
with self.subTest(image_format=image_format):
with self.assertRaises(ValueError):
self.faker.image(image_format=image_format) # type: ignore
self.faker.image(image_format=image_format)

def test_docx(self) -> None:
with self.subTest("All params None, should fail"):
Expand Down Expand Up @@ -2793,7 +2793,7 @@ def save(self, *args, **kwargs):
def objects(cls):
"""Mimicking Django's Manager behaviour."""
return DjangoManager(
instance=cls( # noqa
instance=cls( # type: ignore
id=FAKER.pyint(),
username=FAKER.username(),
first_name=FAKER.first_name(),
Expand Down Expand Up @@ -2828,7 +2828,7 @@ def save(self, *args, **kwargs):
def objects(cls):
"""Mimicking Django's Manager behaviour."""
return DjangoManager(
instance=cls( # noqa
instance=cls( # type: ignore
id=FAKER.pyint(),
title=FAKER.word(),
slug=FAKER.slug(),
Expand Down Expand Up @@ -2898,7 +2898,7 @@ class ArticleFactory(ModelFactory):
minutes_to_read = FACTORY.pyint( # type: ignore
min_value=1, max_value=10
)
author = SubFactory(UserFactory) # type: ignore
author = SubFactory(UserFactory)

class Meta:
model = Article
Expand Down Expand Up @@ -3315,7 +3315,7 @@ def first(self):
return None

if self.model == SQLAlchemyUser:
return self.model( # noqa
return self.model( # type: ignore
id=FAKER.pyint(),
username=FAKER.username(),
first_name=FAKER.first_name(),
Expand All @@ -3325,7 +3325,7 @@ def first(self):
date_joined=FAKER.date_time(),
)
elif self.model == SQLAlchemyArticle:
return self.model( # noqa
return self.model( # type: ignore
id=FAKER.pyint(),
title=FAKER.word(),
slug=FAKER.slug(),
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,7 @@ exclude_lines = [
]

[tool.mypy]
check_untyped_defs = true
warn_unused_ignores = true
warn_redundant_casts = true
warn_unused_configs = true

0 comments on commit af0325b

Please sign in to comment.