-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsimple_module.py
More file actions
77 lines (55 loc) · 1.62 KB
/
Copy pathsimple_module.py
File metadata and controls
77 lines (55 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""A simple Python module for testing the parser."""
import os
from collections import OrderedDict
from typing import List, Optional
class Animal:
"""Base class for animals."""
def __init__(self, name: str, age: int):
"""Initialize an animal."""
self.name = name
self.age = age
def speak(self) -> str:
"""Make a sound."""
return ""
def _internal_method(self):
"""A private-by-convention method."""
pass
def __private_method(self):
"""A name-mangled private method."""
pass
class Dog(Animal):
"""A dog that inherits from Animal."""
def speak(self) -> str:
return f"{self.name} says Woof!"
async def fetch_data(url: str) -> dict:
"""Fetch data from a URL asynchronously."""
if url.startswith("http"):
return {"status": "ok"}
return {"status": "error"}
def process_items(items: List[str]) -> int:
"""Process a list of items with some complexity."""
count = 0
for item in items:
if item.startswith("a"):
count += 1
elif item.startswith("b"):
count += 2
else:
for char in item:
if char.isdigit():
count += 10
return count
def _private_helper():
"""A module-level private function."""
pass
def __very_private():
"""A module-level very private function."""
pass
def test_animals():
"""Test function for animals."""
dog = Dog("Rex", 5)
assert dog.speak() == "Rex says Woof!"
def generator_func():
"""A generator function."""
for i in range(10):
yield i * 2