Skip to content

Commit

Permalink
fix docstring and add check to clean_doc_string
Browse files Browse the repository at this point in the history
  • Loading branch information
noajshu committed Mar 16, 2024
1 parent 75c9ddb commit 7407f28
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
8 changes: 4 additions & 4 deletions doc/python_api_reference_vDev.md
Original file line number Diff line number Diff line change
Expand Up @@ -2412,14 +2412,14 @@ def likeliest_error_sat_problem(
Examples:
>>> import stim
>>> circuit = stim.Circuit("""
>>> circuit = stim.Circuit('''
... X_ERROR(0.1) 0
... M 0
... OBSERVABLE_INCLUDE(0) rec[-1]
... X_ERROR(0.4) 0
... M 0
... DETECTOR rec[-1] rec[-2]
... """)
... ''')
>>> print(circuit.likeliest_error_sat_problem(
... quantization=1000
... ), end='')
Expand Down Expand Up @@ -2793,14 +2793,14 @@ def shortest_error_sat_problem(
Examples:
>>> import stim
>>> circuit = stim.Circuit("""
>>> circuit = stim.Circuit('''
... X_ERROR(0.1) 0
... M 0
... OBSERVABLE_INCLUDE(0) rec[-1]
... X_ERROR(0.4) 0
... M 0
... DETECTOR rec[-1] rec[-2]
... """)
... ''')
>>> print(circuit.shortest_error_sat_problem(), end='')
p wcnf 2 4 5
1 -1 0
Expand Down
8 changes: 4 additions & 4 deletions doc/stim.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1781,14 +1781,14 @@ class Circuit:
Examples:
>>> import stim
>>> circuit = stim.Circuit("""
>>> circuit = stim.Circuit('''
... X_ERROR(0.1) 0
... M 0
... OBSERVABLE_INCLUDE(0) rec[-1]
... X_ERROR(0.4) 0
... M 0
... DETECTOR rec[-1] rec[-2]
... """)
... ''')
>>> print(circuit.likeliest_error_sat_problem(
... quantization=1000
... ), end='')
Expand Down Expand Up @@ -2099,14 +2099,14 @@ class Circuit:
Examples:
>>> import stim
>>> circuit = stim.Circuit("""
>>> circuit = stim.Circuit('''
... X_ERROR(0.1) 0
... M 0
... OBSERVABLE_INCLUDE(0) rec[-1]
... X_ERROR(0.4) 0
... M 0
... DETECTOR rec[-1] rec[-2]
... """)
... ''')
>>> print(circuit.shortest_error_sat_problem(), end='')
p wcnf 2 4 5
1 -1 0
Expand Down
8 changes: 4 additions & 4 deletions glue/python/src/stim/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1781,14 +1781,14 @@ class Circuit:
Examples:
>>> import stim
>>> circuit = stim.Circuit("""
>>> circuit = stim.Circuit('''
... X_ERROR(0.1) 0
... M 0
... OBSERVABLE_INCLUDE(0) rec[-1]
... X_ERROR(0.4) 0
... M 0
... DETECTOR rec[-1] rec[-2]
... """)
... ''')
>>> print(circuit.likeliest_error_sat_problem(
... quantization=1000
... ), end='')
Expand Down Expand Up @@ -2099,14 +2099,14 @@ class Circuit:
Examples:
>>> import stim
>>> circuit = stim.Circuit("""
>>> circuit = stim.Circuit('''
... X_ERROR(0.1) 0
... M 0
... OBSERVABLE_INCLUDE(0) rec[-1]
... X_ERROR(0.4) 0
... M 0
... DETECTOR rec[-1] rec[-2]
... """)
... ''')
>>> print(circuit.shortest_error_sat_problem(), end='')
p wcnf 2 4 5
1 -1 0
Expand Down
8 changes: 4 additions & 4 deletions src/stim/circuit/circuit.pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2113,14 +2113,14 @@ void stim_pybind::pybind_circuit_methods(pybind11::module &, pybind11::class_<Ci
Examples:
>>> import stim
>>> circuit = stim.Circuit("""
>>> circuit = stim.Circuit('''
... X_ERROR(0.1) 0
... M 0
... OBSERVABLE_INCLUDE(0) rec[-1]
... X_ERROR(0.4) 0
... M 0
... DETECTOR rec[-1] rec[-2]
... """)
... ''')
>>> print(circuit.shortest_error_sat_problem(), end='')
p wcnf 2 4 5
1 -1 0
Expand Down Expand Up @@ -2194,14 +2194,14 @@ void stim_pybind::pybind_circuit_methods(pybind11::module &, pybind11::class_<Ci
Examples:
>>> import stim
>>> circuit = stim.Circuit("""
>>> circuit = stim.Circuit('''
... X_ERROR(0.1) 0
... M 0
... OBSERVABLE_INCLUDE(0) rec[-1]
... X_ERROR(0.4) 0
... M 0
... DETECTOR rec[-1] rec[-2]
... """)
... ''')
>>> print(circuit.likeliest_error_sat_problem(
... quantization=1000
... ), end='')
Expand Down
7 changes: 6 additions & 1 deletion src/stim/cmd/command_help.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ std::string stim::clean_doc_string(const char *c, bool allow_too_long) {
}
line_length++;
}
const char *start_of_line = result.c_str() + result.size() - line_length - 1;
if (strstr(start_of_line, "\"\"\"") != nullptr) {
std::stringstream ss;
ss << "Docstring line contains \"\"\" (please use ''' instead):\n" << start_of_line << "\n";
throw std::invalid_argument(ss.str());
}
if (!allow_too_long && line_length > 80) {
const char *start_of_line = result.c_str() + result.size() - line_length - 1;
if (memcmp(start_of_line, "@signature", strlen("@signature")) != 0 &&
memcmp(start_of_line, "@overload", strlen("@overload")) != 0 &&
strstr(start_of_line, "https://") == nullptr) {
Expand Down

0 comments on commit 7407f28

Please sign in to comment.