Repository: amogorkon/justuse (language: python)

Issue:
Refactored use_path and cleaned up __init__.py



Discussion / hints:

Fix patch:
diff --git a/src/use/pydantics.py b/src/use/pydantics.py
index 18e15d28..c4bf81b9 100644
--- a/src/use/pydantics.py
+++ b/src/use/pydantics.py
@@ -50,11 +50,11 @@ class Config:
 
 
 class Version(PkgVersion):
-    def __new__(cls, *args, **kwargs):
+    def __new__(self, *args, **kwargs):
         if args and isinstance(args[0], Version):
             return args[0]
         else:
-            return super(cls, Version).__new__(cls)
+            return super(self, Version).__new__(self)
 
     def __init__(self, versionobj: Optional[Union[PkgVersion, str]] = None, *, major=0, minor=0, patch=0):
         if isinstance(versionobj, Version):


Test patch:
diff --git a/src/.test8.py b/src/.test8.py
index 6264a685..4eab8319 100644
--- a/src/.test8.py
+++ b/src/.test8.py
@@ -86,55 +86,55 @@ def is_compatible(pre, post):
         
     def check(x, y):
         print(f"checking {x} {type(x)} => {y} {type(y)}")
-        # narrowing {(Any => Any) | (Any => something)} is OK
         if x is Any:
             return True
-        else:
-            # broadening (something => Any) is NOK
-            if y is Any:
-                return False
-            # now to the more specific cases (something => something else)
-            else:
-                # let's first check if we're dealing with numbers
-                try:
-                    if issubclass(x, Number) and issubclass(y, Number):
-                        # since the generic implementations aren't actual subclasses of each other
-                        # we have to map to the numeric tower classes
-                        for X in numerics:
-                            if issubclass(x, X):
-                                break
-                        x = X
-                        for Y in numerics:
-                            if issubclass(y, Y):
-                                break
-                        y = Y
-                except TypeError:  # issubclass is allergic to container classes (types.GenericAlias)
-                    pass
-                
-                # the other important type hierarchy are containers
-                # let's check if the user is using typing classes and educate them to use collections.abc instead
-                if x.__module__ == "typing":
-                    x = getattr(collections.abc, str(x).split(".")[-1])
-                    warn(NotComparableWarning(f"{x} is of a type from the typing module, which can't be compared. Please use a type from collections.abc instead.")) 
-                if y.__module__ == "typing":
-                    y = getattr(collections.abc, str(y).split(".")[-1])
-                    warn(NotComparableWarning(f"{y} is of a type from the typing module, which can't be compared. Please use a type from collections.abc instead.")) 
-                
-                X = get_origin(x)
-                Y = get_origin(y)
-                if X is not None and Y is not None:
+        if y is Any:
+            return False
+        # let's first check if we're dealing with numbers
+        try:
+            if issubclass(x, Number) and issubclass(y, Number):
+                # since the generic implementations aren't actual subclasses of each other
+                # we have to map to the numeric tower classes
+                for X in numerics:
+                    if issubclass(x, X):
+                        break
+                x = X
+                for Y in numerics:
+                    if issubclass(y, Y):
+                        break
+                y = Y
+        except TypeError:  # issubclass is allergic to container classes (types.GenericAlias)
+            pass
+
+        # the other important type hierarchy are containers
+        # let's check if the user is using typing classes and educate them to use collections.abc instead
+        if x.__module__ == "typing":
+            x = getattr(collections.abc, str(x).split(".")[-1])
+            warn(NotComparableWarning(f"{x} is of a type from the typing module, which can't be compared. Please use a type from collections.abc instead."))
+        if y.__module__ == "typing":
+            y = getattr(collections.abc, str(y).split(".")[-1])
+            warn(NotComparableWarning(f"{y} is of a type from the typing module, which can't be compared. Please use a type from collections.abc instead.")) 
+
+        X = get_origin(x)
+        Y = get_origin(y)
+        if X is not None and Y is not None:
                     # (Sequence => list) is OK, (list => Sequence) is NOK
-                    if issubclass(Y, X):
-                        # (list[int] => Sequence[int]) -> (int => int)
-                        return all(check(x_, y_) for x_, y_ in zip_longest(get_args(x), get_args(y), fillvalue=Any))
-                    else:
-                        return False
-                    
-                try:
-                    # (x => y) where y is not a subclass of x is NOK
-                    return issubclass(y, x)
-                except TypeError:  # (int => list[int]) or (list[int] => int) NOK
-                    return False
+            return (
+                all(
+                    check(x_, y_)
+                    for x_, y_ in zip_longest(
+                        get_args(x), get_args(y), fillvalue=Any
+                    )
+                )
+                if issubclass(Y, X)
+                else False
+            )
+
+        try:
+            # (x => y) where y is not a subclass of x is NOK
+            return issubclass(y, x)
+        except TypeError:  # (int => list[int]) or (list[int] => int) NOK
+            return False
 
     return all(check(x, y) for x, y in zip_longest(pre_sig, post_sig, fillvalue=Any))
         
diff --git a/tests/.tests/.test2.py b/tests/.tests/.test2.py
index 9895e185..a5f39912 100644
--- a/tests/.tests/.test2.py
+++ b/tests/.tests/.test2.py
@@ -178,13 +178,14 @@ def test_gaussmf():
     lambda: [3, 3, 4],
     lambda: [],
     lambda: list({0, 1, 2, 3, ...}),
-    lambda: list({3, 9, 9}),
+    lambda: list({3, 9}),
     lambda: list(set()),
     lambda: [],
     lambda: [1, 2, 1, 1],
     lambda: sleep(0.5),
 ]
 
+
 from collections import defaultdict
 import inspect
 
@@ -206,7 +207,7 @@ def test_bool2():
 
 
 def test_tuple():
-    return 3 in (1,3)
+    return 3 in {1, 3}
 
 def test_set():
     return 3 in {1,3}
diff --git a/tests/test.py b/tests/test.py
index 4ec769a7..9ab79a9c 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -1,4 +1,4 @@
 s = 'abcdefgabcd'
 set(s)
 
-print(''.join(x for x in s if not x in set(s)))
\ No newline at end of file
+print(''.join(x for x in s if x not in set(s)))
\ No newline at end of file