Skip to content

Strict typing - #103

Merged
Dreamsorcerer merged 22 commits into
masterfrom
strict-typing
Mar 17, 2025
Merged

Dreamsorcerer merged 22 commits into
masterfrom
strict-typing

Conversation

@Dreamsorcerer

@Dreamsorcerer Dreamsorcerer commented Mar 16, 2025 •

Copy link
Copy Markdown
Member

Fixes #53. Probably fixes #81.

Comment thread src/propcache/_helpers_py.py Fixed
Comment thread tests/test_cached_property.py Fixed
Comment thread tests/test_cached_property.py Fixed

@overload
def __get__(self, inst: _TSelf[_T], owner: Optional[type[object]] = None) -> _T: ...
def __get__(self, inst: _CacheImpl, owner: Optional[type[object]] = None) -> _T: ...

Check notice

Code scanning / CodeQL

Statement has no effect

This statement has no effect.

Copilot Autofix

AI over 1 year ago

To fix the problem, we need to remove the ellipsis (...) on line 41 and ensure that the method signature is correctly defined. The ellipsis is likely a placeholder that was mistakenly left in the code. We should replace it with the appropriate method signature that matches the intended functionality.

  • Remove the ellipsis (...) on line 41.
  • Ensure that the method signature for the __get__ method is correctly defined.
Suggested changeset 1
src/propcache/_helpers_py.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/propcache/_helpers_py.py b/src/propcache/_helpers_py.py
--- a/src/propcache/_helpers_py.py
+++ b/src/propcache/_helpers_py.py
@@ -40,3 +40,3 @@
     @overload
-    def __get__(self, inst: _CacheImpl, owner: Optional[type[object]] = None) -> _T: ...
+    def __get__(self, inst: _CacheImpl, owner: Optional[type[object]] = None) -> _T: 
 
EOF
@@ -40,3 +40,3 @@
@overload
def __get__(self, inst: _CacheImpl, owner: Optional[type[object]] = None) -> _T: ...
def __get__(self, inst: _CacheImpl, owner: Optional[type[object]] = None) -> _T:

Copilot is powered by AI and may make mistakes. Always verify output.
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Mar 16, 2025
@codspeed

codspeed Bot commented Mar 16, 2025 •

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #103 will not alter performance

Comparing strict-typing (e8c62ad) with master (d44bb30)

Summary

✅ 4 untouched benchmarks

@codecov

codecov Bot commented Mar 16, 2025 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 89.89899% with 10 lines in your changes missing coverage. Please review.

Project coverage is 97.66%. Comparing base (d44bb30) to head (e8c62ad).
Report is 19 commits behind head on master.

Files with missing lines Patch % Lines
packaging/pep517_backend/_backend.py 88.88% 1 Missing and 1 partial ⚠️
packaging/pep517_backend/_cython_configuration.py 83.33% 2 Missing ⚠️
packaging/pep517_backend/cli.py 60.00% 2 Missing ⚠️
packaging/pep517_backend/_compat.py 87.50% 1 Missing ⚠️
src/propcache/_helpers_py.py 83.33% 0 Missing and 1 partial ⚠️
tests/test_cached_property.py 93.33% 0 Missing and 1 partial ⚠️
tests/test_under_cached_property.py 95.83% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #103      +/-   ##
==========================================
+ Coverage   88.99%   97.66%   +8.66%     
==========================================
  Files          18       18              
  Lines         745      770      +25     
  Branches       75       40      -35     
==========================================
+ Hits          663      752      +89     
+ Misses         64       10      -54     
+ Partials       18        8      -10     
Flag Coverage Δ
CI-GHA 97.66% <89.89%> (+8.66%) ⬆️
MyPy 93.06% <83.33%> (+14.52%) ⬆️
OS-Linux 97.58% <87.17%> (-1.33%) ⬇️
OS-Windows 93.43% <86.84%> (-1.44%) ⬇️
OS-macOS 94.08% <87.17%> (-1.29%) ⬇️
Py-3.10.11 92.47% <74.35%> (-2.63%) ⬇️
Py-3.10.16 94.62% <74.35%> (-2.66%) ⬇️
Py-3.11.11 95.96% <87.17%> (-1.31%) ⬇️
Py-3.11.9 93.81% <87.17%> (-1.28%) ⬇️
Py-3.12.8 ?
Py-3.12.9 95.96% <87.17%> (-1.31%) ⬇️
Py-3.13.1 95.52% <86.84%> (-1.76%) ⬇️
Py-3.13.2 95.96% <87.17%> (-1.31%) ⬇️
Py-3.9.13 92.45% <74.35%> (-2.63%) ⬇️
Py-3.9.21 94.60% <74.35%> (-2.66%) ⬇️
Py-pypy7.3.16 93.71% <68.42%> (-2.96%) ⬇️
Py-pypy7.3.18 ?
Py-pypy7.3.19 93.73% <68.42%> (-2.95%) ⬇️
VM-macos-latest 94.08% <87.17%> (-1.29%) ⬇️
VM-ubuntu-latest 97.58% <87.17%> (-1.33%) ⬇️
VM-windows-latest 93.43% <86.84%> (-1.44%) ⬇️
pytest 97.58% <87.17%> (-1.33%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

class APIProtocol(Protocol):
def cached_property(
self, func: Callable[[Any], _T_co]
) -> cached_property[_T_co]: ...

Check notice

Code scanning / CodeQL

Statement has no effect

This statement has no effect.

Copilot Autofix

AI over 1 year ago

To fix the problem, we should replace the ellipsis with a pass statement. This will make it clear that the method is intentionally left without an implementation, which is a common practice in abstract base classes or protocols. The pass statement is a no-op (no operation) statement in Python, which means it does nothing but is syntactically valid.

Suggested changeset 1
tests/test_cached_property.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/tests/test_cached_property.py b/tests/test_cached_property.py
--- a/tests/test_cached_property.py
+++ b/tests/test_cached_property.py
@@ -18,3 +18,3 @@
         self, func: Callable[[Any], _T_co]
-    ) -> cached_property[_T_co]: ...
+    ) -> cached_property[_T_co]: pass
 
EOF
@@ -18,3 +18,3 @@
self, func: Callable[[Any], _T_co]
) -> cached_property[_T_co]: ...
) -> cached_property[_T_co]: pass

Copilot is powered by AI and may make mistakes. Always verify output.
class APIProtocol(Protocol):
def under_cached_property(
self, func: Callable[[Any], _T_co]
) -> under_cached_property[_T_co]: ...

Check notice

Code scanning / CodeQL

Statement has no effect

This statement has no effect.

Copilot Autofix

AI over 1 year ago

To fix the problem, we need to replace the ellipsis with a proper implementation or an abstract method declaration. Since this is a protocol, the method should be marked as abstract to indicate that it must be implemented by any subclass. We can use the abc module to achieve this.

  • Replace the ellipsis with pass to indicate that the method has no implementation in the protocol itself.
  • Import ABC and abstractmethod from the abc module.
  • Modify the APIProtocol class to inherit from ABC and mark the under_cached_property method as abstract.
Suggested changeset 1
tests/test_under_cached_property.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/tests/test_under_cached_property.py b/tests/test_under_cached_property.py
--- a/tests/test_under_cached_property.py
+++ b/tests/test_under_cached_property.py
@@ -13,7 +13,9 @@
 
+from abc import ABC, abstractmethod
 
-class APIProtocol(Protocol):
+class APIProtocol(ABC, Protocol):
+    @abstractmethod
     def under_cached_property(
         self, func: Callable[[Any], _T_co]
-    ) -> under_cached_property[_T_co]: ...
+    ) -> under_cached_property[_T_co]: pass
 
EOF
@@ -13,7 +13,9 @@

from abc import ABC, abstractmethod

class APIProtocol(Protocol):
class APIProtocol(ABC, Protocol):
@abstractmethod
def under_cached_property(
self, func: Callable[[Any], _T_co]
) -> under_cached_property[_T_co]: ...
) -> under_cached_property[_T_co]: pass

Copilot is powered by AI and may make mistakes. Always verify output.
@Dreamsorcerer
Dreamsorcerer merged commit eb64b65 into master Mar 17, 2025
@Dreamsorcerer
Dreamsorcerer deleted the strict-typing branch March 17, 2025 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decorator doesn't look like a property decorator to pylint Typing issues

2 participants