pnt-functional 0.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ """A Python package template using Nix and uv."""
2
+
3
+ from importlib import metadata
4
+
5
+ from pnt_functional.main import greet
6
+
7
+ try:
8
+ __version__ = metadata.version(__package__)
9
+ except metadata.PackageNotFoundError:
10
+ __version__ = "unknown"
11
+
12
+ del metadata
13
+
14
+ __all__ = [
15
+ "greet",
16
+ ]
pnt_functional/main.py ADDED
@@ -0,0 +1,61 @@
1
+ """Main module for pnt_functional demonstrating functional programming patterns."""
2
+
3
+ from beartype import beartype
4
+ from expression import Error, Ok, Result
5
+
6
+
7
+ @beartype
8
+ def validate_name(name: str) -> Result[str, Error]:
9
+ """Validate a name.
10
+
11
+ Args:
12
+ name: Name to validate
13
+
14
+ Returns:
15
+ Result with validated name or error message
16
+ """
17
+ name = name.strip()
18
+ if not name:
19
+ return Error("Name cannot be empty")
20
+ if len(name) < 2:
21
+ return Error("Name must be at least 2 characters")
22
+ if len(name) > 50:
23
+ return Error("Name must be at most 50 characters")
24
+ return Ok(name.capitalize())
25
+
26
+
27
+ @beartype
28
+ def create_greeting(name: str) -> Result[str, Error]:
29
+ """Create a greeting message.
30
+
31
+ Args:
32
+ name: Name to greet
33
+
34
+ Returns:
35
+ Result with greeting message or error message
36
+ """
37
+ return validate_name(name).bind(lambda n: Ok(f"Hello, {n}!"))
38
+
39
+
40
+ @beartype
41
+ def greet(name: str = "World") -> str:
42
+ """Greet someone by name.
43
+
44
+ Args:
45
+ name: Optional name to greet. Defaults to "World".
46
+
47
+ Returns:
48
+ Greeting message or error message
49
+ """
50
+ greeting = create_greeting(name)
51
+
52
+ match greeting:
53
+ case Result(tag="ok"):
54
+ return greeting.ok
55
+ case Result(tag="error"):
56
+ print(
57
+ f"Verify you've respected the input constraints:\n\n{greeting.error}\n"
58
+ )
59
+ return "This is supposed to be a hello world program, but it failed."
60
+ case _:
61
+ return "The return type is not a Result."
@@ -0,0 +1,52 @@
1
+ """Tests for main module."""
2
+
3
+ from expression import Error, Ok
4
+
5
+ from pnt_functional.main import create_greeting, greet, validate_name
6
+
7
+
8
+ def test_validate_name_valid():
9
+ """Test name validation with valid input."""
10
+ assert validate_name("alice") == Ok("Alice")
11
+ assert validate_name(" bob ") == Ok("Bob")
12
+
13
+
14
+ def test_validate_name_invalid():
15
+ """Test name validation with invalid input."""
16
+ assert validate_name("") == Error("Name cannot be empty")
17
+ assert validate_name(" ") == Error("Name cannot be empty")
18
+ assert validate_name("a") == Error("Name must be at least 2 characters")
19
+ assert validate_name("x" * 51) == Error("Name must be at most 50 characters")
20
+
21
+
22
+ def test_create_greeting_valid():
23
+ """Test greeting creation with valid input."""
24
+ assert create_greeting("alice") == Ok("Hello, Alice!")
25
+ assert create_greeting(" bob ") == Ok("Hello, Bob!")
26
+
27
+
28
+ def test_create_greeting_invalid():
29
+ """Test greeting creation with invalid input."""
30
+ result = create_greeting("")
31
+ assert result.is_error()
32
+
33
+ result = create_greeting("a")
34
+ assert result.is_error()
35
+
36
+
37
+ def test_greet_default():
38
+ """Test greet function with default argument."""
39
+ result = greet()
40
+ assert result == "Hello, World!"
41
+
42
+
43
+ def test_greet_custom():
44
+ """Test greet function with custom name."""
45
+ result = greet("Alice")
46
+ assert result == "Hello, Alice!"
47
+
48
+
49
+ def test_greet_invalid():
50
+ """Test greet function with invalid input."""
51
+ result = greet("a")
52
+ assert result == "This is supposed to be a hello world program, but it failed."
@@ -0,0 +1,15 @@
1
+ Metadata-Version: 2.4
2
+ Name: pnt-functional
3
+ Version: 0.0.0
4
+ Summary: A Python package template using Nix and uv
5
+ Author-email: Your Name <your.email@example.com>
6
+ License: Apache-2.0
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Requires-Python: <3.13,>=3.11
14
+ Requires-Dist: beartype<0.20.0,>=0.19.0
15
+ Requires-Dist: expression>=5.5.0
@@ -0,0 +1,7 @@
1
+ pnt_functional/__init__.py,sha256=BEbTN5USqweO36kEt0_dJGpGFucSSvzSizGyJDT3UEs,283
2
+ pnt_functional/main.py,sha256=y6X6viEwdI4UGQ9P1EBPY9UVlUEkE1TvWBxdY-TNJdg,1565
3
+ pnt_functional/tests/test_main.py,sha256=uvEnodo7z6ijdwvLyQ1WfmtSxe8bO6gHlw6Lr44vepI,1569
4
+ pnt_functional-0.0.0.dist-info/METADATA,sha256=QjcAMXzTTqEkKwxH12twGBpLt1chwxUjsYUFWjJ2cns,574
5
+ pnt_functional-0.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
+ pnt_functional-0.0.0.dist-info/entry_points.txt,sha256=qyufpe1pBeed6C9OxvyFHBb_T5ptnYo175uUdal2utI,61
7
+ pnt_functional-0.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pnt-functional = pnt_functional.main:greet